package com.kanasco.engg.dao;

import java.util.ArrayList;
import java.util.List;

import org.springframework.orm.hibernate3.HibernateTemplate;

import bb.access.po.BuyerCode;
import bb.access.po.Part;
import bb.access.po.PartType;
import bb.access.po.Unit;
import bb.access.po.WeightUnit;
import bb.common.PartPK;
import bb.common.PartVO;



public class ItemDao implements IItemDao{
	
	private HibernateTemplate hibernateTemplate;

	public void insertItem(Part part){
		hibernateTemplate.save(part);
		
	}
	
public void updateItems(Part part){
	hibernateTemplate.update(part);
}
	public List<String> getAllItemTypes(){
		List itemList = new ArrayList();
		List<PartType> itemTypeList = hibernateTemplate.find("from bb.access.po.PartType");
		System.out.println("getAllItemList is:"+itemTypeList.size());
		for (PartType item: itemTypeList) {
			itemList.add(item.getPartType());
		}
		return itemList;
	}
	public List<String> getAllItemUOMs(){
		List unitList=new ArrayList();
		List<Unit> itemUnitList=hibernateTemplate.find("from bb.access.po.Unit");
		
		System.out.println("Unit list size::"+itemUnitList.size());
		for(Unit unit:itemUnitList){
			unitList.add(unit.getUnitName());
			System.out.println("unitList"+unitList);
		}
		return unitList;
	}
	public List<Part> getAllItemList(){
		
	
		List<Part> partList= hibernateTemplate.find("from bb.access.po.Part");
		
	return partList;
	}
	public List<String> getAllItemShippingWtUnits(){
		List ShippingWtUnitList=new ArrayList();
		List<WeightUnit> swuList=hibernateTemplate.find("from bb.access.po.WeightUnit");
		System.out.println("shippint list"+swuList.size());
		for(WeightUnit wtUnit:swuList){
			ShippingWtUnitList.add(wtUnit.getWeightUnitName());
			
		}
		return ShippingWtUnitList;
	}
	
	public List<String> getAllBuyerCode(){
		List buyerCodeList=new ArrayList();
		List<BuyerCode> byrcodeList=hibernateTemplate.find("from bb.access.po.BuyerCode");
		System.out.println("BuyerCode list size::"+byrcodeList.size());
		System.out.println("BuyerCode list size::"+byrcodeList);
		for(BuyerCode buyer:byrcodeList){
			buyerCodeList.add(buyer.getBuyerName());
			System.out.println("buyerCodeList"+buyerCodeList);
		}
		return buyerCodeList;
	}
	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}
	
}
